package com.cby.android.library.mvi

import androidx.lifecycle.LiveData
import kotlinx.coroutines.channels.Channel
import java.lang.RuntimeException

/**
 * @description: mvi
 * @author: ChenBaoYang
 * @createDate: 2022/4/28 3:29 下午
 */
interface IIntent {
}

interface IState {

}

interface IBaseState : IState{
    var errorMsg: String?
}

/**
 * 基本页面状态：加载中，加载成功，空数据，加载失败
 */
sealed class PageStatus : IState{
    object Loading : PageStatus()
    object Success : PageStatus()
    object Empty: PageStatus()
    data class Error(val error: ApiError) : PageStatus()
}

class ApiError(message: String?): RuntimeException(message)

interface IModel<S: IState, I: IIntent> {
    val intents: Channel<I>
    val state: LiveData<S>
}